<template>
  <div class="asset-return">
    <group class="form-group">
      <cell title="创建人" :value="info.name" is-link></cell>
      <cell title="创建人所在部门" :value="info.dept" is-link></cell>
      <wx-select-person title="盘点人" @getPersonList="getPersonList"></wx-select-person>
      <wx-select-dept
        title="盘点人所在部门"
        @getDepartmentList="getDepartmentList"
      ></wx-select-dept>
      <!-- <cell title="盘点人" :value="info.transferName" is-link></cell>
        <cell title="盘点人所在部门" :value="info.dept" is-link></cell> -->
      <!-- <cell title="转移后位置" :value="info.position" is-link></cell> -->
      <x-input
        title="盘点批次"
        required
        v-model="info.number"
        text-align="right"
        name="lot"
        placeholder="请输入盘点批次"
      ></x-input>
      <x-textarea
        class="mark"
        :max="20"
        v-model="info.checkTitle"
        placeholder="请输入盘点标题，20字以内"
      >
        <div slot="label">盘点标题</div>
      </x-textarea>
      <!-- <cell title="盘点批次" :value="info.lot" is-link></cell> -->
    </group>
    <loading :show="isLoading"></loading>
    <div class="count-list">
      <div>盘点明细：共计{{ list.length }}条</div>
      <div class="count-list-collapse" @click="collapse = !collapse">
        <span>{{ collapse ? "收起" : "展开" }} </span>
        <x-icon class="more" v-show="collapse" type="ios-arrow-up"></x-icon>
        <x-icon class="more" v-show="!collapse" type="ios-arrow-down"></x-icon>
      </div>
    </div>
    <asset-list :list="list" v-show="!collapse"></asset-list>
    <div class="submit-box">
      <x-button class="submit-btn" @click.native="submit">提交</x-button>
    </div>
  </div>
</template>

<script>
import WxSelectDept from "@/components/common/wx-select-dept";
import WxSelectPerson from "@/components/common/wx-select-person";
import AssetList from "../components/asset-list";
import { Group, XInput, Cell, Datetime, XTextarea, XButton, Loading } from "vux";
import AssetApi from "@/api/asset.js";
export default {
  components: {
    WxSelectDept,
    WxSelectPerson,
    AssetList,
    Group,
    XInput,
    Cell,
    Datetime,
    XTextarea,
    XButton,
    Loading
  },
  data() {
    return {
      info: {
        name: this.$store.state.user.userInfo.name,
        dept: this.$store.state.user.userInfo.depName,
        checkTitle: "",
        number: "", //盘点批次
        checkDep: "", //盘点人所在部门id
        checkDepName: "", //盘点人所在部门名称
        checkUser: "", //盘点人用户id
        checkUserName: "", //盘点人用户名称
      },
      collapse: false,
      total: 3,
      list: [],
      isLoading:false,
    };
  },
  mounted() {
    let selectIdList = this.$route.params.ids.split(",");
    console.log(56, selectIdList);
    this.getList(selectIdList);
  },
  methods: {
    getList(selectIdList) {
      let _params = {
        page: 1,
        pageSize: 10000,
        assetCode: this.$route.params.name,
      };
      this.isLoading = true
      AssetApi.findClassAll(_params).then((res) => {
        this.isLoading = false
        if (res.code == "0000") {
          let _list = res.data.records;
          this.list = _list.filter((item) => selectIdList.includes(item.assetId));
        }
      });
    },

    getDepartmentList(value) {
      let deptIds = value[0].id;
      let deptNames = value[0].name;
      this.info.checkDepName = deptNames.toString();
      this.info.checkDep = deptIds.toString();
    },
    getPersonList(value) {
      let userIds = value[0].id; // 已选的单个成员ID
      let userNames = value[0].name; // 已选的单个成员ID
      this.info.checkUserName = userNames.toString();
      this.info.checkUser = userIds.toString();
    },
    submit() {
      let _params = {
        assetIds: this.$route.params.ids,
        // assetNames: this.$route.params.names,
        checkDep: this.info.checkDep, //盘点人所在部门id
        checkDepName: this.info.checkDepName, //盘点人所在部门名称
        checkUser: this.info.checkUser, //盘点人用户id
        checkUserName: this.info.checkUserName, //盘点人用户名称
        number: this.info.number,
        checkTitle: this.info.checkTitle,
      };
      if (!_params.number) {
        this.$vux.toast.show({
          text: "请输入盘点批次",
          type: "warn",
        });
        return
      } else if (!_params.checkTitle) {
        this.$vux.toast.show({
          text: "请输入盘点名称",
          type: "warn",
        });
        return
      }
      AssetApi.assetCheckAdd(_params).then((res) => {
        if (res.code == "0000") {
          this.$vux.toast.show({
            text: "资产已提交盘点",
          });
          this.$router.push({ name: 'inventory', query:{all:true}});
        }
      });
    },
  },
};
</script>

<style lang="less">
.mark {
  flex-wrap: wrap;
  padding: 15px 15px 10px 20px !important;
  .weui-cell__hd {
    width: 100%;
    height: 20px;
    line-height: 20px;
    // margin-top: 10px;
    color: #101010;
  }
}
.count-list {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 36px;
  line-height: 36px;
  background: #f1f1f1;
  padding: 0 20px;
  font-size: 14px;
  .count-list-collapse {
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }
}
.asset-return {
  padding-bottom: 60px;

  .submit-box {
    position: fixed;
    bottom: 0;
    width: 100%;
    padding: 10px 0;
    background: #fff;
    z-index: 100;
    .submit-btn {
      width: 260px;
      border-radius: 20px;
      color: #fff;
      margin: 0 auto;
      border-color: rgb(205, 166, 105);
      background: rgb(205, 166, 105);
    }
  }
}
</style>
